Ubuntu

想要執行在 80 上執行 SSL 的 8080 埠現有伺服器塊?

  • March 8, 2017

我已經在 80 上執行我的網站,並且想打開另一個埠說 8080,但是當我輸入“ https://papa.fit:8080 ”時它不起作用。

伺服器塊papa.fit

server {
   listen 80;
   listen [::]:80;

   server_name papa.fit www.papa.fit;

   return 301 https://$server_name$request_uri;
}


server {

   listen 443 ssl;
   listen [::]:443 ssl;



   root /var/www/waev.in;

   # Add index.php to the list if you are using PHP
   index index.html index.php index.htm index.nginx-debian.html;

   server_name papa.fit www.papa.fit;
       include snippets/ssl-papa.fit.conf;
       include snippets/ssl-params.conf;

#set client body size to 2M#
#       client max body size 2M;


   location / {
       # First attempt to serve request as file, then
       # as directory, then fall back to displaying a 404.
       try_files $uri $uri/ =404;
   }

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

   location ~ \.php$ {
       include snippets/fastcgi-php.conf;

       # With php7.0-cgi alone:
       #fastcgi_pass 127.0.0.1:9000;
       # With php7.0-fpm:
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
   }

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   location ~ /\.ht {
       deny all;
   }

   location /phpmyadmin {
          root /usr/share/;
          index index.php index.html index.htm;
          location ~ ^/phpmyadmin/(.+\.php)$ {
                  try_files $uri =404;
                  root /usr/share/;
                  fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include /etc/nginx/fastcgi_params;
          }
          location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                  root /usr/share/;
          }
   }


}

server {
   listen 8080;
   listen [::]:8080;

   server_name papa.fit www.papa.fit;

   root /var/www/laravel_api/public/demo/;
   index index.php index.html;

   location / {
       try_files $uri $uri/ /index.php?$query_string;
   }

   location ~ \.php$ {
       try_files $uri /index.php =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
   }
}

您缺少ssl指令以及證書配置。

改變

listen 8080;
listen [::]:8080;

listen 8080 ssl;
listen [::]:8080 ssl;

並將其添加到塊中:

include snippets/ssl-papa.fit.conf;
include snippets/ssl-params.conf;

您沒有在文章中包含這些文件,所以我們不知道其中有什麼,但我們假設它只是證書配置。在這種情況下,它應該足夠了。

引用自:https://serverfault.com/questions/836943