主網域多埠存取
#在dns nameserver設定a記錄
將 指向伺服器ip
開放所需端口,修改nginx設定檔
#例如我們有兩個服務分別開放在80端口和8080端口
如果有iptable,先開放埠:
iptables -a input -ptcp --dport 80 -j accept iptables -a input -ptcp --dport 8080 -j accept
修改設定檔:
#path: /usr/local/nginx/conf/nginx.conf server { listen 80; server_name www.xxx.com; access_log /data/www/log/33.33.33.33_nginx.log combined; index index.html index.htm index.php; include /usr/local/nginx/conf/rewrite/none.conf; root /data/www/website/33.33.33.33:80; location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } } server { listen 8080; server_name a.xxx.com; access_log /data/www/log/33.33.33.33:8080_nginx.log combined; index index.html index.htm index.php; include /usr/local/nginx/conf/rewrite/none.conf; root /data/www/website/33.33.33.33:8080; location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } }
關鍵就是兩個 server 段配置,你也可以把這兩段拆成兩個配置文件,放到
/etc/nginx/conf.d/
目錄下面;
子網域多埠存取
增加一筆a記錄
##將a.xxx.com 指向伺服器ip
#path: /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.xxx.com;
access_log /data/www/log/33.33.33.33_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/www/website/33.33.33.33:80;
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
server {
listen 80;
listen [::]:80;
server_name a.xxx.com;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header connection 'upgrade';
proxy_set_header host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ =404;
}
}
nginx -s reload
以上是Nginx如何設定多埠多網域存取的詳細內容。更多資訊請關注PHP中文網其他相關文章!