nginx一个端口配置多域名服务

【nginx一个端口配置多域名服务】花门楼前见秋草,岂能贫贱相看老。这篇文章主要讲述nginx一个端口配置多域名服务相关的知识,希望能为你提供帮助。

本文演示如何在一个端口上配置多个域名。

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
#通用的内容可以放在http层配置。
log_formatmain$remote_addr - $remote_user [$time_local] "$request"
$status $body_bytes_sent "$http_referer"
"$http_user_agent" "$http_x_forwarded_for";

tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
types_hash_max_size 2048;
include/etc/nginx/mime.types;
default_typeapplication/octet-stream;

#配置https服务
server
listen 443 ssl;
server_namewww.mydomain.net;
root/var/www/html;

ssl_certificate/etc/nginx/cert/pem220223.pem;
ssl_certificate_key/etc/nginx/cert/key220223.key;
ssl_session_timeout5m;

ssi on;
ssi_silent_errors on;
ssi_types text/shtml;

location /
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET, POST, OPTIONS;
add_header Access-Control-Allow-Headers DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;


error_page 404 /404.html;
location = /404.html


error_page 500 502 503 504 /50x.html;
location = /50x.html



#默认的http服务
server
listen80 default_server;
listen[::]:80 default_server;
server_name_;
root/var/www/html;

ssi on;
#ssi_silent_errors on;
ssi_types text/shtml;
# Load configuration files for the default server block.

location /
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET, POST, OPTIONS;
add_header Access-Control-Allow-Headers DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization;


error_page 404 /404.html;
location = /404.html


error_page 500 502 503 504 /50x.html;
location = /50x.html



#配置一个http服务
server
listen80;
server_namesub1.mydomain.net; #多个域名使用空格隔开,或者使用通配符
root/var/www/html2;
indexindex.php index.html index.htm;

ssi on;
#ssi_silent_errors on;
ssi_types text/shtml;
# Load configuration files for the default server block.

location ~ \\.php$
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
includefastcgi_params;


error_page 404 /404.html;
location = /404.html


error_page 500 502 503 504 /50x.html;
location = /50x.html



#还可以添加更多域名


    推荐阅读