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

Posted 北京王老师

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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_format main $remote_addr - $remote_user [$time_local] "$request"
$status $body_bytes_sent "$http_referer"
"$http_user_agent" "$http_x_forwarded_for";

tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;

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

ssl_certificate /etc/nginx/cert/pem220223.pem;
ssl_certificate_key /etc/nginx/cert/key220223.key;
ssl_session_timeout 5m;

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
listen 80 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
listen 80;
server_name sub1.mydomain.net; #多个域名使用空格隔开,或者使用通配符
root /var/www/html2;
index index.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_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;


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


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



#还可以添加更多域名

以上是关于nginx一个端口配置多域名服务的主要内容,如果未能解决你的问题,请参考以下文章

[Nginx]-外部多端口映射Https443端口配置

Nginx配置将二级域名解析到Linux服务器指定端口

Nginx如何配置多个服务域名解析共用80端口详解

Nginx配置——单域名反向代理多个端口

nginx根据域名转发

搭建后台环境nginx http 配置二级域名