Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of nginx configuring multiple sites to share Port 80

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Just change one place and add the directory of the virtual host configuration file you want to reference in the http module:

For example: include / usr/local/nginx/default.d/*.conf

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; include / usr/local/nginx/default.d/*.conf; / / just add one line here}

2. Set up the virtual host configuration directory:

Create a default.d folder under / usr/local/nginx/ to specifically place the configuration files for the site.

Post a copy of my configuration:

/ usr/local/nginx/default.d/mytest.conf

Server {listen 80; / / Note here, the default default_server should be removed, because we need to configure domain name access separately below, so do not leave default_server here, otherwise an error will be reported. Server_name mytest.com; / / write the domain name you want to set, you can write more than one, and the name is separated by a space root / mnt/share/mytest.com; / / here is the root directory of your virtual machine, write the absolute path # Load configuration files for the default server block. Location / {index index.php index.html index.htm; / / configure the default visited page} location ~ *\ .php$ {/ / configure php to parse .php file fastcgi_index index.php; fastcgi_pass 127.0.0.1 php$ 9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;} error_page 404 / 404.html / / default error page location = / 40x.html {} error_page 500 502 503 504 / 50x.htl; location = / 50x.html {}}

One more:

Server {listen 80; server_name www.mytest1.com; root / var/www/html; index index.html index.htm index.php; location / {try_files $uri $uri/ / index.php?$query_string;} location = / favicon.ico {log_not_found off;} location ~\ .php$ {fastcgi_pass 127.0.0.1 var/www/html; index index.html index.htm index.php; location 9000 Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}}

3, also want to build other virtual machines, the same, copy the above file, modify the places I marked can!

4. After the virtual machine configuration file is configured, you need to add the above domain name under the hosts file under linux, otherwise you will still access the public network.

Vim / etc/hosts127.0.0.1 mytest1.com127.0.0.1 mytest.com

5. If we want to visit the website under the linux in the virtual machine under windows, then configure the hosts file under windows. All domain names point to the linux server, for example:

192.168.0.27 mytest1.com192.168.0.27 mytest.com

6. Problems encountered:

Nginx: [emerg] a duplicate default server for 0.0.0.0:80 in / etc/nginx/vhosts/

When you encounter this problem, it must be:

Server {listen 80

Everything after 80 in this place is removed, leaving only the port number 80. Removing it will solve the problem.

Summary

The above is the solution of nginx configuring multiple sites to share port 80, which is introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report