User Tools

Site Tools


linux:nginx

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:nginx [2014/04/24 22:48] – created percylinux:nginx [2016/05/05 13:07] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Nginx Config ====== ====== Nginx Config ======
-This page is used record some notes when I config a VPS running with Nginx.+This page is used to record some notes when I config a VPS running with Nginx.
  
 ===== Create a new server block ===== ===== Create a new server block =====
Line 10: Line 10:
    listen 80;    listen 80;
    root /var/www/team/;    root /var/www/team/;
 +   server_name  team.pjq.me;
 Then enable this site: Then enable this site:
   ln -s /etc/nginx/sites-available/team.pjq.me.conf /etc/nginx/sites-enabled/   ln -s /etc/nginx/sites-available/team.pjq.me.conf /etc/nginx/sites-enabled/
   /etc/init.d/nginx restart   /etc/init.d/nginx restart
 So the site is running, cheers. So the site is running, cheers.
 +===== Enable directory list =====
 +Add "autoindex on;"
 +<code>
 + location / {
 +                # First attempt to serve request as file, then
 +                # as directory, then fall back to displaying a 404.
 +                try_files $uri $uri/ =404;
 +                # Uncomment to enable naxsi on this location
 +                # include /etc/nginx/naxsi.rules
 +                autoindex on;
 +        }
 +</code>
 +
 +===== Revert Proxy =====
 +<code>
 +server {
 +        server_name wechat.pjq.me;
 +        location / {
 +                proxy_set_header   X-Real-IP $remote_addr;
 +                proxy_set_header   Host      $http_host;
 +                proxy_pass http://127.0.0.1:8080;
 +        }
 +        location /doc/ {
 +                alias /usr/share/doc/;
 +                autoindex on;
 +                allow 127.0.0.1;
 +                deny all;
 +        }
 +}
 +
 +</code>
 +
 +===== Enable php =====
 +   apt-get install php5-fpm
 +  /etc/init.d/php5-fpm restart
 +
 +<code>
 + grep -v -E "#|^$" /etc/nginx/sites-available/ef.pjq.me.conf 
 +server {
 + listen 80;
 + root /var/www/ef/;
 + index index.html index.htm;
 + server_name  ef.pjq.me;
 + location / {
 + try_files $uri $uri/ =404;
 +                autoindex on;
 + }
 + location ~ \.php$ {
 + fastcgi_split_path_info ^(.+\.php)(/.+)$;
 + fastcgi_pass unix:/var/run/php5-fpm.sock;
 + fastcgi_index index.php;
 + include fastcgi_params;
 + }
 +}
 +
 +</code>
 +
 +
 +===== nginx all https =====
 +To enable redirect all the http request to https
 +    rewrite ^(.*) https://$host$1 permanent;    
 +==== generate the ssl certificate ====
 +
 +  mkdir /etc/nginx/ssl
 +  sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
 +
 +
 +<code file=proxy.pjq.me.conf>
 +server {
 + listen 80;
 + root /var/www/knProxy/;
 + index index.html index.htm index.php;
 + server_name  proxy.pjq.me;
 +    rewrite ^(.*) https://$host$1 permanent;
 + location / {
 + try_files $uri $uri/ =404;
 +                autoindex on;
 + }
 + location ~ \.php$ {
 + fastcgi_split_path_info ^(.+\.php)(/.+)$;
 + fastcgi_pass unix:/var/run/php5-fpm.sock;
 + fastcgi_index index.php;
 + include fastcgi_params;
 + }
 +}
 +server {
 +    listen 443 ssl;
 + root /var/www/knProxy/;
 + index index.html index.htm index.php;
 + server_name  proxy.pjq.me;
 +    ssl_certificate /etc/nginx/ssl/nginx.crt;
 +    ssl_certificate_key /etc/nginx/ssl/nginx.key;
 + location / {
 + try_files $uri $uri/ =404;
 +                autoindex on;
 + }
 + location ~ \.php$ {
 + fastcgi_split_path_info ^(.+\.php)(/.+)$;
 + fastcgi_pass unix:/var/run/php5-fpm.sock;
 + fastcgi_index index.php;
 + include fastcgi_params;
 + }
 +}
 +</code>
 +
/var/www/dokuwiki/wiki/data/attic/linux/nginx.1398350883.txt.gz · Last modified: 2016/05/05 13:06 (external edit)