小白 问个 NGINX 配置子域名问题
需求: 同一IP, 80端口,多个子域名访问a.xxx.com 指向目录 var/www/html/a.xxx.com
b.xxx.com 指向目录 var/www/html/b.xxx.com
我的做法是 修改 etc/nginx/sites-avaliable/default如下
server {
listen 80 ;
listen [::]:80 ;
server_name a.xxx.com ;
root /var/www/html/a.xxx.com;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80 ;
listen [::]:80 ;
server_name b.xxx.com ;
root /var/www/html/b.xxx.com;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
问题是 nginx 无法成功重启,有错误,将第二个 80端口 改成其他可以正常启动,但是域名访问失效,只能通过端口来区分访问目录,在网上搜了一大把,没有一个靠谱的,这应该是最基础的了吧,往大神指点一二。不甚感激,搞得头大! 试一试分开写
/etc/nginx/sites-avaliable/a
/etc/nginx/sites-avaliable/b
然后分别软连接到/etc/nginx/sites-enable 好的,我回去试试。谢谢大佬 试了下,不成功。 在第一个server的80端口后面加上reuse,具体的可以查看手册 server {
listen 80reuse ;
listen [::]:80 ;
结果:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
whk0425 发表于 2018-9-14 17:51
server {
listen 80reuse ;
listen [::]:80 ;
是 reuseport,记错了,不是reuse。。。
我一般会加一个default server,其他的server正常写,可以省好多麻烦
[*]server {
[*] listen 80 fastopen=3 reuseport default;
[*] listen [::]:80fastopen=3 reuseport default;
[*] server_name _;
[*]}复制代码
qytang 发表于 2018-9-14 18:13
是 reuseport,记错了,不是reuse。。。
我一般会加一个default server,其他的server正常写,可以省好多 ...
谢谢大佬,搞定了,感激涕零!!!!
页:
[1]