How to config NGINX server block work with port and directory in same time?
I am using CentOS Linux release 7.6.1810 (Core), NGINX 1.12.2, VPS has ip 103.48.111.34
I have two domains: foo.com and bar.com . Domain control at GoDaddy.
http://foo.com use ASP.NET Core, can access at http://localhost:5000
http://bar.com use Wordpress version 5, put at /etc/home/bar
PHP 7 is work ok.
The content of /etc/nginx/nginx.conf
is
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
The content of /etc/nginx/sites-available/bar.com
is
server {
listen 80;
listen [::]:80;
root /home/bar/;
index index.html index.htm index.php;
server_name bar.com www.bar.com;
location / {
try_files $uri $uri/ =404;
}
}
then
sudo ln -s /etc/nginx/sites-available/bar.com /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
service nginx status
Then I edit file /etc/hosts
. The content of /etc/nginx/nginx.conf
is
103.48.111.34 bar.com www.bar.com
103.48.111.34 foo.vn www.foo.vn
I am using client Windows 10 pro, I run ipconfig /flushdns
and clear web browser cache. Try to access http://foo.com and http://bar.com , result: http://foo.com work ok, http://bar.com always point to the content of http://foo.com
How to config NGINX server block work with 1 site use port, and 1 site use directory, in same VPS?
centos nginx
add a comment |
I am using CentOS Linux release 7.6.1810 (Core), NGINX 1.12.2, VPS has ip 103.48.111.34
I have two domains: foo.com and bar.com . Domain control at GoDaddy.
http://foo.com use ASP.NET Core, can access at http://localhost:5000
http://bar.com use Wordpress version 5, put at /etc/home/bar
PHP 7 is work ok.
The content of /etc/nginx/nginx.conf
is
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
The content of /etc/nginx/sites-available/bar.com
is
server {
listen 80;
listen [::]:80;
root /home/bar/;
index index.html index.htm index.php;
server_name bar.com www.bar.com;
location / {
try_files $uri $uri/ =404;
}
}
then
sudo ln -s /etc/nginx/sites-available/bar.com /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
service nginx status
Then I edit file /etc/hosts
. The content of /etc/nginx/nginx.conf
is
103.48.111.34 bar.com www.bar.com
103.48.111.34 foo.vn www.foo.vn
I am using client Windows 10 pro, I run ipconfig /flushdns
and clear web browser cache. Try to access http://foo.com and http://bar.com , result: http://foo.com work ok, http://bar.com always point to the content of http://foo.com
How to config NGINX server block work with 1 site use port, and 1 site use directory, in same VPS?
centos nginx
add a comment |
I am using CentOS Linux release 7.6.1810 (Core), NGINX 1.12.2, VPS has ip 103.48.111.34
I have two domains: foo.com and bar.com . Domain control at GoDaddy.
http://foo.com use ASP.NET Core, can access at http://localhost:5000
http://bar.com use Wordpress version 5, put at /etc/home/bar
PHP 7 is work ok.
The content of /etc/nginx/nginx.conf
is
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
The content of /etc/nginx/sites-available/bar.com
is
server {
listen 80;
listen [::]:80;
root /home/bar/;
index index.html index.htm index.php;
server_name bar.com www.bar.com;
location / {
try_files $uri $uri/ =404;
}
}
then
sudo ln -s /etc/nginx/sites-available/bar.com /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
service nginx status
Then I edit file /etc/hosts
. The content of /etc/nginx/nginx.conf
is
103.48.111.34 bar.com www.bar.com
103.48.111.34 foo.vn www.foo.vn
I am using client Windows 10 pro, I run ipconfig /flushdns
and clear web browser cache. Try to access http://foo.com and http://bar.com , result: http://foo.com work ok, http://bar.com always point to the content of http://foo.com
How to config NGINX server block work with 1 site use port, and 1 site use directory, in same VPS?
centos nginx
I am using CentOS Linux release 7.6.1810 (Core), NGINX 1.12.2, VPS has ip 103.48.111.34
I have two domains: foo.com and bar.com . Domain control at GoDaddy.
http://foo.com use ASP.NET Core, can access at http://localhost:5000
http://bar.com use Wordpress version 5, put at /etc/home/bar
PHP 7 is work ok.
The content of /etc/nginx/nginx.conf
is
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
The content of /etc/nginx/sites-available/bar.com
is
server {
listen 80;
listen [::]:80;
root /home/bar/;
index index.html index.htm index.php;
server_name bar.com www.bar.com;
location / {
try_files $uri $uri/ =404;
}
}
then
sudo ln -s /etc/nginx/sites-available/bar.com /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
service nginx status
Then I edit file /etc/hosts
. The content of /etc/nginx/nginx.conf
is
103.48.111.34 bar.com www.bar.com
103.48.111.34 foo.vn www.foo.vn
I am using client Windows 10 pro, I run ipconfig /flushdns
and clear web browser cache. Try to access http://foo.com and http://bar.com , result: http://foo.com work ok, http://bar.com always point to the content of http://foo.com
How to config NGINX server block work with 1 site use port, and 1 site use directory, in same VPS?
centos nginx
centos nginx
edited 10 hours ago
foobarfuu
asked 10 hours ago
foobarfuufoobarfuu
1013
1013
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505330%2fhow-to-config-nginx-server-block-work-with-port-and-directory-in-same-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505330%2fhow-to-config-nginx-server-block-work-with-port-and-directory-in-same-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown