Home > Article > Operation and Maintenance > How to configure second-level domain name in nginx
My vps has three services, which are:
The blog service built by wordpress, running on port 8000, accessed via http ://fangyuanxiaozhan.com:8000
git service built by gogs, running on port 10080, access method http://fangyuanxiaozhan.com:10080
The network disk service built by nextcloud runs on port 8080. The access method is http://fangyuanxiaozhan.com:10080
##My needs:
2. I am using centos7, and the default location of the nginx configuration file is
/etc/nginx/nginx .conf , interestingly,
/etc/nginx/nginx.conf introduces the configuration folder
/etc/nginx/conf.d , that is, we can put # Comment out some default configurations in ##/etc/nginx/nginx.conf
and configure multiple independent configuration files directly in the folder /etc/nginx/conf.d
.
Configuration <pre class="brush:plain;"># for more information on configuration, see:
# * official english documentation: http://nginx.org/en/docs/
# * official russian documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
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 &#39;$remote_addr - $remote_user [$time_local] "$request" &#39;
&#39;$status $body_bytes_sent "$http_referer" &#39;
&#39;"$http_user_agent" "$http_x_forwarded_for"&#39;;
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;
include /etc/nginx/conf.d/*.conf;
}</pre>
Pay attention to the last line of the above configuration file,
ensures that under /etc/nginx/conf.d/
, all configuration files ending with .conf will be included in the main configuration file nginx .conf
is introduced and takes effectYou need to create three new files under
blog.conf (realizes port 8000 mapping to port 80, without using the second-level domain name)
server { listen 80; server_name fangyuanxiaozhan.com; location / { proxy_set_header x-real-ip $remote_addr; proxy_set_header host $http_host; proxy_pass http://0.0.0.0:8000; } }
blog.conf realizes mapping fangyuanxiaozhan.com:8000 to fangyuanxiaozhan.com
git.conf (Realizing port 10080 to port 80, using the second-level domain name
git)<pre class="brush:bash;">server {
listen 80;
server_name git.fangyuanxiaozhan.com;
location / {
proxy_set_header x-real-ip $remote_addr;
proxy_set_header host $http_host;
proxy_pass http://0.0.0.0:10080;
}
}</pre>
git.conf implements mapping of fangyuanxiaozhan.com:10080 to git.fangyuanxiaozhan.com
nc.conf (realizes port 10080 mapping to port 80, using the second-level domain name
cloud )<pre class="brush:bash;">server {
listen 80;
server_name cloud.fangyuanxiaozhan.com;
location / {
proxy_set_header x-real-ip $remote_addr;
proxy_set_header host $http_host;
proxy_pass http://0.0.0.0:8080;
}
}</pre>
git.conf realizes mapping fangyuanxiaozhan.com:8080 to cloud.fangyuanxiaozhan.com
Close nginx
sudo $(which nginx) -s stop
Open nginx
sudo $(which nginx)
Effect display
The above is the detailed content of How to configure second-level domain name in nginx. For more information, please follow other related articles on the PHP Chinese website!