Nginx multi-port forwarding file configuration
It’s uncomfortable to add a port number to the server using a port other than 80, and it is not cost-effective to use domain name resolution to bind. For example, there are only two anonymous forwarding url services in the free version of Alibaba Cloud. If you use Nginx for forwarding, it is still very cool. .
You only need to resolve all the second-level domain names to the server's IP (Alibaba Cloud domain name resolution to IP is not much restricted), use Nginx to identify the accessed domain name, forward it, and experience the domain name resolution service without losing it. Here is an example of the configuration file currently in use
# 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/doc/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;
#网页使用nginx上传文件时的最大文件限制
client_max_body_size 20m;
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;
#一条转发记录,一个server
server {
listen 80; #监听的端口
listen [::]:80;
#服务名写入你的域名,例如二级域名,只需要在云解析服务把所有二级域
#名解析到服务器的IP,在这里会进行服务名(访问的域名)匹配
#例如以域名 t.test.com访问,就会匹配到以下服务名
server_name t.test.com;
#你的需要转发的跟目录,也就是你的显示的页面的目录,算是
#index.html的文件夹,例如存在/var/www/html/test/index.html
#则根目录可以写成/var/www/html/test
root /var/www/html/test;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
#进入文件夹检索的转发的界面文件,左边的优先
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
listen [::]:80;
#例如t2.test.com
server_name t2.test.com;
#需要转发/var/www/html/t2/index.html
root /var/www/html/t2;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
#转发php网页,需要安装并开启php的组件
server {
listen 80;
listen [::]:80;
#例如php.test.com
server_name php.test.com;
#如果需要转发/var/www/html/php/index.php
root /var/www/html/php;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.php index.html index.htm;
}
location ~ .php$ {
root /usr/share/nginx/html/wordpress; #将/usr/share/nginx/html替换为您的网站根目录,本教程使用/usr/share/nginx/html作为网站根目录
fastcgi_pass 127.0.0.1:9000; #Nginx通过本机的9000端口将PHP请求转发给PHP-FPM进行处理
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; #Nginx调用fastcgi接口处理PHP请求
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 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 {
# }
# }
}