Home  >  Article  >  Backend Development  >  Problem with nginx configuring multiple sites?

Problem with nginx configuring multiple sites?

WBOY
WBOYOriginal
2016-08-25 10:37:181034browse

I use nginx to configure two sites. One site should be configured for https access and the other for http access?

server {

<code>    listen       443;
    server_name  www.gzjjhd.com;
    
    
    ssl on;
    ssl_certificate E:/webserver/nginx/sslkey/wosign.com.crt;
    ssl_certificate_key E:/webserver/nginx/sslkey/wosign.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_prefer_server_ciphers on;


    location / {
        root   E:/www/jsd;
        index  index.php index.html index.htm;
    }

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

    location ~ \.php$ {
        root           E:/www/jsd;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

server {
    listen       80;
    server_name app.gzjjhd.com;

    location / {
        root   E:/www/HDWeb;
        index  index.php index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    
    include E:/www/HDWeb/rewrite.conf;
    
    location ~ \.php$ {
        root           E:/www/HDWeb;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
</code>

After I configure it like this, app.gzjjhd.com becomes https://appgzjjhd.com for access. But I don't want this. I want to http://app.gzjjhd.com and ask the masters how to modify it!

Reply content:

I use nginx to configure two sites. One site should be configured for https access and the other for http access?

server {

<code>    listen       443;
    server_name  www.gzjjhd.com;
    
    
    ssl on;
    ssl_certificate E:/webserver/nginx/sslkey/wosign.com.crt;
    ssl_certificate_key E:/webserver/nginx/sslkey/wosign.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_prefer_server_ciphers on;


    location / {
        root   E:/www/jsd;
        index  index.php index.html index.htm;
    }

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

    location ~ \.php$ {
        root           E:/www/jsd;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

server {
    listen       80;
    server_name app.gzjjhd.com;

    location / {
        root   E:/www/HDWeb;
        index  index.php index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    
    include E:/www/HDWeb/rewrite.conf;
    
    location ~ \.php$ {
        root           E:/www/HDWeb;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
</code>

After I configure it like this, app.gzjjhd.com becomes https://appgzjjhd.com for access. But I don't want this. I want to http://app.gzjjhd.com and ask the masters how to modify it!

Use two site configuration files respectively

It turns out that my port 443 is occupied

Configure multiple sites, which means virtual host. The same server loads multiple sites. Configure the virtual host in ngixn. Just add a server{} directly to the main configuration file, imitating the server that comes with it. Parameters

<code>78    server {
79        listen 80;
80    #    listen somename:8080;
81        server_name www.xuping.com;
82        root /usr/share/nginx/xuping;
83        index index.html index.htm;
84    
85        location / {
86            try_files $uri $uri/ =404;
87        }
88        location ~ \.php$ {
89            fastcgi_split_path_info ^(.+\.php)(/.+)$;
90            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
91        
92            # With php5-cgi alone:
93        #    fastcgi_pass 127.0.0.1:9000;
94        #    # With php5-fpm:
95            fastcgi_pass unix:/var/run/php5-fpm.sock;
96            fastcgi_index index.php;
97            include fastcgi_params;
98        }
99    </code>

100 # deny access to .htaccess files, if Apache's document root
101 # concurs with nginx's one
102 #
103 location ~ /.ht {
104 deny all;
105 }
106 }

Just set the port number and rules directly here.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn